#include "tinyxml2.h"
#include <iostream>
#include <vector>
#include <regex>
using namespace tinyxml2;
using namespace std;

struct RssItem
{
    string title;
    string link;
    string description;
    string content;
};

class RssReader
{
public:
    RssReader();
    void parseRss();//解析
    void dump(const string & filename);//输出
private:
    vector<RssItem> _rss;
};   

int main(){
    cout << "begin" << endl;
    XMLDocument doc;
    doc.LoadFile("H:/Code/C++/cpp/cpp09/rss/coolshell.xml");
    if (doc.ErrorID()){
        cout << "加载 XML 失败！错误码：" << doc.ErrorID() << "，原因：" << doc.ErrorName() << endl;
        return -1;
    }

    XMLElement* itemNode = doc.FirstChildElement("rss")->FirstChildElement("channel")->FirstChildElement("item");
    cout << itemNode << endl;


    while(itemNode){
        string title = itemNode->FirstChildElement("title")->GetText();
        cout << "title = " << title << endl;

        string link = itemNode->FirstChildElement("link")->GetText();
        cout << "link = " << link << endl;

        string description = itemNode->FirstChildElement("description")->GetText();
        cout << "description = " << description << endl;

        string content = itemNode->FirstChildElement("content")->GetText();
        cout << "content = " << content << endl;

        regex reg("<[^>]+>");
        description = regex_replace(description, reg, "");
        content = regex_replace(content, reg, "");

        itemNode = itemNode->NextSiblingElement("item");
    }
    cout << "over" << endl;

    return 0;
}